﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using System.Linq;
using System.Collections.Generic;
namespace Exact_Extension
{
    public partial class StudentAddressLabel : DevExpress.XtraReports.UI.XtraReport
    {
        ExactDataContext DS;
        public StudentAddressLabel(ExactDataContext _DS)
        {
            InitializeComponent();
            DS = _DS;
            this.LoadData();
        }
        private void LoadData()
        {
            List<ISHCMC_V_StudentListWithDebtor> ListStudent = new List<ISHCMC_V_StudentListWithDebtor>();
            var query = from ST in DS.ISHCMC_V_StudentListWithDebtors
                        where ST.School == "ISHCMC" && ST.InvoiceDisplayID >=700 && ST.InvoiceDisplayID <=799
                        orderby ST.InvoiceDisplayID
                        select ST;
            foreach (ISHCMC_V_StudentListWithDebtor itemStudent in query)
            {
                var querycc = from CC in DS.cicmpies
                              where CC.debnr == itemStudent.InvoiceDebtor
                              select CC;
                if (querycc.Count() > 0)
                {
                    cicmpy itemCC = querycc.First();

                    itemStudent.Email1 = "To: "+ itemCC.cmp_name;
                    if (itemStudent.Attention == null || itemStudent.Attention.Length <= 0)
                    {
                    }
                    else
                    {
                        itemStudent.Attention = "Att: " + itemStudent.Attention;
                    }
                    if (itemStudent.BillingAddress1 == null || itemStudent.BillingAddress1.Length <= 0)
                    {
                        itemStudent.BillingAddress1 = itemCC.cmp_fadd1;
                        itemStudent.BillingAddress2 = itemCC.cmp_fadd2;
                        itemStudent.BillingAddress3 = itemCC.cmp_fadd3;
                    }
                    ListStudent.Add(itemStudent);
                }
            }

            this.bindingSource1.DataSource = ListStudent;
        }

    }
}
